package com.atom.app.mvvm.net.interceptor

import com.atom.app.mvvm.Contacts
import com.tencent.mmkv.MMKV
import okhttp3.Interceptor
import okhttp3.Response

class TokenInterceptor : Interceptor {
    val mmkv: MMKV = MMKV.defaultMMKV()

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val path = request.url.toUrl().path
        val builder = request.newBuilder()
        if (!path.contains("login")) {
            builder.addHeader(
                "Authorization",
                "Bearer ${mmkv.decodeString(Contacts.net_access_token) ?: ""}"
            )
        }
        return chain.proceed(builder.build())
    }
}
